package cn.yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.yunhe.biz.IScoreBiz;
import cn.yunhe.biz.ScoreBizImpl;
import cn.yunhe.entity.Enroll_in_province;



/**
 * Servlet implementation class DoUser
 */
public class DoEnroll extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoEnroll() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
		HttpSession session = request.getSession();
		PrintWriter out =response.getWriter();
		IScoreBiz isb = new ScoreBizImpl();
		
		String opt = request.getParameter("opt");
		if("add".equals(opt)){
			String major = request.getParameter("major");
			String se_num = request.getParameter("e_num");
			String se_avg = request.getParameter("e_avg");
			String se_low = request.getParameter("e_low");
			String se_uni = request.getParameter("e_uni");
			String se_pro = request.getParameter("e_pro");
			String swenorli = request.getParameter("wenorli");
			
			int wenorli = Integer.parseInt(swenorli);
			int e_pro = Integer.parseInt(se_pro);
			int e_uni = Integer.parseInt(se_uni);
			int e_num = Integer.parseInt(se_num);
			int e_avg = Integer.parseInt(se_avg);
			int e_low = Integer.parseInt(se_low);
			
			boolean r=isb.add(major,wenorli,e_pro,e_uni,e_num,e_avg,e_low);
			response.sendRedirect("DoBackstage?opt=getScore");
		}else if("update".equals(opt)){
			String se_id = request.getParameter("e_id");
			String major = request.getParameter("major");
			String se_num = request.getParameter("e_num");
			String se_avg = request.getParameter("e_avg");
			String se_low = request.getParameter("e_low");
			String se_uni = request.getParameter("e_uni");
			String se_pro = request.getParameter("e_pro");
			String swenorli = request.getParameter("wenorli");
			
			int e_id = Integer.parseInt(se_id);
			int wenorli = Integer.parseInt(swenorli);
			int e_pro = Integer.parseInt(se_pro);
			int e_uni = Integer.parseInt(se_uni);
			int e_num = Integer.parseInt(se_num);
			int e_avg = Integer.parseInt(se_avg);
			int e_low = Integer.parseInt(se_low);
			
			
			
			boolean r= isb.update(major,wenorli,e_pro,e_uni,e_num,e_avg,e_low,e_id);
			response.sendRedirect("DoBackstage?opt=getScore");
		}else if("del".equals(opt)){
			String se_id = request.getParameter("eid");
			int e_id = Integer.parseInt(se_id);
			
			boolean r = isb.del(e_id);
			response.sendRedirect("DoBackstage?opt=getScore");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
